package cn.internship.modules.manage.controller;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import cn.internship.modules.manage.entity.dto.ClassInfoSearch;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.internship.modules.manage.entity.ClassInfoEntity;
import cn.internship.modules.manage.service.ClassInfoService;
import cn.internship.common.utils.PageUtils;
import cn.internship.common.utils.R;



/**
 * 
 *
 * @author haha
 * @email haha@gmail.com
 * @date 2023-02-20 15:58:08
 */
@RestController
@RequestMapping("manage/classinfo")
public class ClassInfoController {
    @Autowired
    private ClassInfoService classInfoService;

//    /**
//     * 列表
//     */
//    @RequestMapping("/list")
//    @RequiresPermissions("manage:classinfo:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = classInfoService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("manage:classinfo:list")
    public R list(ClassInfoSearch search){
        PageUtils page = classInfoService.listByPage(search);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("manage:classinfo:info")
    public R info(@PathVariable("id") Integer id){
		ClassInfoEntity classInfo = classInfoService.getById(id);

        return R.ok().put("classInfo", classInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("manage:classinfo:save")
    public R save(@RequestBody ClassInfoEntity classInfo){
        classInfo.setCreateTime(new Date());
		classInfoService.save(classInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("manage:classinfo:update")
    public R update(@RequestBody ClassInfoEntity classInfo){
		classInfoService.updateById(classInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("manage:classinfo:delete")
    public R delete(@RequestBody Integer[] ids){
		classInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 下拉列表
     * @return
     */
    @RequestMapping("/dropList")
    public R dropList(){
        return R.ok().put("data",classInfoService.list());
    }

}
